import { _decorator, Component, Node } from 'cc'
const { ccclass, property } = _decorator

// 抽象基类，定义了单例的行为
export default abstract class Singleton {
  private static instances: { [key: string]: any } = {}

  // Ctor:通常用作一个参数名，代表构造函数（constructor）
  public static getInstance<T>(ctor: new () => T): T {
    const instanceName = ctor.name
    if (!Singleton.instances[instanceName]) {
      Singleton.instances[instanceName] = new ctor()
    }
    return Singleton.instances[instanceName] as T
  }

  public displayTest() {
    console.info('Singleton.displayTest')
  }
}
